﻿
using Xacml.Core;
using System;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class AttributeSelectorElement : AttributeReferenceBase
  {
    private string _requestContextPath;

    public string RequestContextPath
    {
      get
      {
        return this._requestContextPath;
      }
      set
      {
        this._requestContextPath = value;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    public AttributeSelectorElement(XmlReader reader, XacmlVersion version)
      : base(reader, version)
    {
      if (reader.LocalName == "AttributeSelector" && this.ValidateSchema(reader, version))
        this._requestContextPath = reader.GetAttribute("RequestContextPath");
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    public AttributeSelectorElement(string dataType, bool mustBePresent, string requestContextPath, XacmlVersion schemaVersion)
      : base(dataType, mustBePresent, schemaVersion)
    {
      this._requestContextPath = requestContextPath;
    }

    public override void WriteDocument(XmlWriter writer)
    {
      writer.WriteStartElement("AttributeSelector");
      writer.WriteAttributeString("RequestContextPath", this._requestContextPath);
      writer.WriteAttributeString("DataType", this.DataType);
      writer.WriteEndElement();
    }
  }
}
